<?php
namespace app\audit_api\controller;


use app\constdir\ApiConst;
use think\Controller;

class Base extends Controller
{
    /*
     * 成功返回提示
     */
    public function apiSuccess($message , $data = null,$page =null){
        return collection([
            'status' => ApiConst::SUCCESS_CODE,
            'msg' => $message,
            'data' => $data,
            'page' => $page
        ]);
    }

    /*
 * 错误提示
 */
    public function apiError($message,$code = ApiConst::FAILED_CODE,$data=null){
        return collection([
                'status' => $code,
                'msg' => $message,
                'data' => $data,
            ]
        );
    }


    /**
     * 集成成功和错误提示综合处理数据   (看情况选用)
     */

    public function apiSuccessError($info = null , $page = null){
        if(empty($info['code'])){
            return $this->apiSuccess(ApiConst::SUCCESS_CODE_MSG,$info ,$page);
        }else{
            return $this->apiError($info['msg'],$info['code']);
        }
    }
}